﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;
using System.Collections.Generic;


namespace Bango.WindowsPhone8.SDK
{
	public class BangoAgentImpl
	{
		public BangoLogger bangoLogger = new BangoLogger();
		
		public static int TOTAL_LEVELS = 10;
		private string[][] _logging_level_events = new string[TOTAL_LEVELS][];
		private List<int> _active_logging_level = new List<int>();
		public int _setLoggingLevel = BangoConstants.SETTING_LOGGING_LEVEL;

		public BangoAgentImpl()
		{
			this.bangoLogger = new BangoLogger();			
		}

		#region Properties

		/// <summary>
		/// The method used to distribute the application.
		/// </summary>
		/// <param name="applicationChannel">The method used to distribute the application, for example "AppStore".</param>
		public void setApplicationChannel(System.String applicationChannel)
		{
			this.bangoLogger.ApplicationChannel = applicationChannel;
		}

		/// <summary>
		/// Gets the method used to distribute the application.
		/// </summary>
		/// <returns>The method used to distribute the application, for example "AppStore".</returns>
		public System.String getApplicationChannel()
		{
			return this.bangoLogger.ApplicationChannel;
		}

		/// <summary>
		/// Sets the type of application.
		/// </summary>
		/// <param name="applicationType">The type of application, for example "Lite".</param>
		public void setApplicationType(System.String applicationType)
		{
			this.bangoLogger.ApplicationType = applicationType;

		}

		/// <summary>
		/// Gets the type of application.
		/// </summary>
		/// <returns>The type of application, for example "Lite".</returns>
		public System.String getApplicationType()
		{
			return this.bangoLogger.ApplicationType;
		}

		/// <summary>
		/// The application version to be used, if this is not supplied then the application version number of the application is used.
		/// </summary>
		/// <param name="applicationVersion">The application version to be used.</param>
		public void setApplicationVersion(System.String applicationVersion)
		{
			this.bangoLogger.ApplicationVersion = applicationVersion;
		}

		/// <summary>
		/// Gets the application version to be used.
		/// </summary>
		/// <returns>The application version to be used.</returns>
		public System.String getApplicationVersion()
		{
			return this.bangoLogger.ApplicationVersion;
		}

		/// <summary>
		/// The period in seconds, that after we receive onSessionEnd call we will still count events in that of the previous session.
		/// </summary>
		/// <param name="continueSessionSeconds">This is the period in seconds.</param>
		public void setContinueSessionSeconds(System.Int32 continueSessionSeconds)
		{
			this.bangoLogger.SessionResumePeriod = continueSessionSeconds;
		}

		/// <summary>
		/// Gets the period in seconds, that after we receive onSessionEnd call we will still count events in that of the previous session.
		/// </summary>
		/// <returns>The period in seconds</returns>
		public System.Int32 getContinueSessionSeconds()
		{
			return this.bangoLogger.SessionResumePeriod;
		}

		/// <summary>
		/// Sets whether or not an attempt should be made to discover the user’s location.
		/// </summary>
		/// <param name="findLocation">Whether or not an attempt should be made to discover the user’s location.</param>
		public void setFindLocation(System.Boolean findLocation)
		{
			this.bangoLogger.FindLocation = findLocation;
		}

		/// <summary>
		/// Gets whether or not an attempt should be made to discover the user’s location.
		/// </summary>
		/// <returns>Whether or not an attempt should be made to discover the user’s location.</returns>
		public System.Boolean getFindLocation()
		{
			return this.bangoLogger.FindLocation;
		}

		/// <summary>
		/// Sets the Location Source method to be used for determining position, possible values are ‘CELL’ and ‘GPS’.
		/// </summary>
		/// <param name="locationSource">The location method to be used.</param>
		public void setLocationSource(System.String locationSource)
		{
			this.bangoLogger.LocationSource = locationSource;
		}

		//public void setLoggingLevel(BangoLoggingLevel.BangoLoggingLevelEnum loggingLevel)
		//{
		//    _active_logging_level = this.bangoLogger.getOrdinalIndices((int)loggingLevel);
		//    this.bangoLogger.setLoggingLevel(loggingLevel);
		//}

		//public void setLoggingLevel(int loggingLevel)
		//{
		//    _active_logging_level = this.bangoLogger.getOrdinalIndices(loggingLevel);
		//    this.bangoLogger.setLoggingLevel(loggingLevel);
		//}

		//public void setLoggingLevelEvents(BangoLoggingLevel.BangoLoggingLevelEnum loggingLevel, string[] eventList)
		//{
		//    this.bangoLogger.setLoggingLevelEvents(loggingLevel, eventList);
		//}


		/// <summary>
		/// Get the Location Source method to be used for determining position.
		/// </summary>
		/// <returns>The location method to be used.</returns>
		public System.String getLocationSource()
		{
			return this.bangoLogger.LocationSource;
		}

		/// <summary>
		/// Enables or disables the logging of events.
		/// </summary>
		/// <param name="logEvents">Should events be logged.</param>
		public void setLogEnabled(System.Boolean logEvents)
		{
			this.bangoLogger.LogEvents = logEvents;
		}

		/// <summary>
		/// Gets whether not events are being logged.
		/// </summary>
		/// <returns>Whether not events are being logged.</returns>
		public System.Boolean getLogEnabled()
		{
			return this.bangoLogger.LogEvents;
		}

		/// <summary>
		/// The URL to post the data to.
		/// </summary>
		/// <param name="postURL">The URL to post the data to.</param>
		public void setPostURL(System.String postURL)
		{
			this.bangoLogger.PostURL = postURL;
		}

		/// <summary>
		/// Whether or not offline storage should be used, the recommend setting for this is true. This will mean that data will not be lost should there be problem transmitting the data.
		/// </summary>
		/// <param name="useOfflineStorage">Should off-line storage be used.</param>
		public void setUseOfflineStorage(System.Boolean useOfflineStorage)
		{
			this.bangoLogger.UseOfflineStorage = useOfflineStorage;
		}

		/// <summary>
		/// Gets whether or not offline storage should be used.
		/// </summary>
		/// <returns>Should off-line storage be used.</returns>
		public System.Boolean getUseOfflineStorage()
		{
			return this.bangoLogger.UseOfflineStorage;
		}

		/// <summary>
		/// Gets the URL to post the data to.
		/// </summary>
		/// <returns>The URL to post the data to.</returns>
		public System.String getPostURL()
		{
			return this.bangoLogger.PostURL;
		}

		/// <summary>
		/// Sets the the User-Agent to be used when posting data.
		/// </summary>
		/// <param name="userAgent">The User-Agent to be used when posting data</param>
		public void setUserAgent(System.String userAgent)
		{
			this.bangoLogger.UserAgent = userAgent;
		}

		/// <summary>
		/// Gets the the User-Agent to be used when posting data.
		/// </summary>
		/// <returns>The User-Agent to be used when posting data</returns>
		public System.String getUserAgent()
		{
			return this.bangoLogger.UserAgent;
		}

		/// <summary>
		/// The unique identifier that you have for the user of the application. For example, this could be an email or a GUID or just a numerical value.
		/// </summary>
		/// <param name="userId">The unique identifier for the user.</param>
		public void setUserId(System.String userId)
		{
			//_bangoLogger.UserId = userId;
			this.bangoLogger.SUserId(userId);
		}

		/// <summary>
		/// Gets the unique identifier for the user of the application.
		/// </summary>
		/// <returns>The unique identifier for the user.</returns>
		public System.String getUserId()
		{
			return this.bangoLogger.UserId;
		}

		public int getMaximumEventsPerProfile()
		{
			return this.bangoLogger.MaximumEventsPerProfile();
		}

		public void setMaximumEventsProfile(int maximumEventsProfile)
		{
			this.bangoLogger.MaximumEventsPerProfile(maximumEventsProfile);
		}

		/// <summary>
		/// Sets the URL to identify the user.
		/// </summary>
		/// <param name="identifierURL">The URL to identify the user.</param>
		public void setIdentifierURL(String identifierURL)
		{
			this.bangoLogger.IdentifierURL = identifierURL;
		}

		/// <summary>
		/// Gets the URL to identify the user.
		/// </summary>
		/// <returns>The URL to identify the user.</returns>
		public String getIdentifierURL()
		{
			return this.bangoLogger.IdentifierURL;
		}

		/// <summary>
		/// Whether to try to identify the bango user id.
		/// </summary>
		/// <param name="identifyBangoUser">Whether to try to identify the bango user id.</param>
		public void setIdentifyBangoUser(Boolean identifyBangoUser)
		{
			this.bangoLogger.IdentifyBangoUser = identifyBangoUser;
		}

		/// <summary>
		/// Gets Whether to try to identify the bango user id.
		/// </summary>
		/// <returns>Whether to try to identify the bango user id.</returns>
		public Boolean getIdentifyBangoUser()
		{
			return this.bangoLogger.IdentifyBangoUser;
		}
		#endregion Properties

		#region Posting Events

		public void postEvents()
		{
			this.bangoLogger.PostEvents(true);
		}

		#endregion

		#region Event logging

		#region Session Events

		#region Start Session

		/// <summary>
		/// Initiates logging, this must be called after the configuration methods but before any other logging or any other session methods.
		/// </summary>
		/// <param name="applicationKey">The Application Key that has been set up for the application using the management tools.</param>
		public void onStartSession(System.String applicationKey)
		{
			onStartSession(applicationKey, null, null, null);
		}

		/// <summary>
		/// Initiates logging, this must be called after the configuration methods but before any other logging or any other session methods.
		/// </summary>
		/// <param name="applicationKey">The Application Key that has been set up for the application using the management tools.</param>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		public void onStartSession(System.String applicationKey, System.String eventValue)
		{
			onStartSession(applicationKey, eventValue, "", null);
		}

		/// <summary>
		/// Initiates logging, this must be called after the configuration methods but before any other logging or any other session methods.
		/// </summary>
		/// <param name="applicationKey">The Application Key that has been set up for the application using the management tools.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onStartSession(System.String applicationKey, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onStartSession(applicationKey, "", "", eventParameters);
		}

		/// <summary>
		/// Initiates logging, this must be called after the configuration methods but before any other logging or any other session methods.
		/// </summary>
		/// <param name="applicationKey">The Application Key that has been set up for the application using the management tools.</param>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		public void onStartSession(System.String applicationKey, System.String eventValue, System.String eventDetail)
		{
			onStartSession(applicationKey, eventValue, eventDetail, null);
		}

		/// <summary>
		/// Initiates logging, this must be called after the configuration methods but before any other logging or any other session methods.
		/// </summary>
		/// <param name="applicationKey">The Application Key that has been set up for the application using the management tools.</param>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onStartSession(System.String applicationKey, System.String eventValue, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<string, string>> eventParameters)
		{
			onStartSession(applicationKey, eventValue, "", eventParameters);
		}

		/// <summary>
		/// Initiates logging, this must be called after the configuration methods but before any other logging or any other session methods.
		/// </summary>
		/// <param name="applicationKey">The Application Key that has been set up for the application using the management tools.</param>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onStartSession(System.String applicationKey, System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{

			if (System.String.IsNullOrEmpty(applicationKey))
			{
				throw new System.ArgumentException("Api key not specified");
			}

			try
			{
				startSession(applicationKey, eventValue, eventDetail, eventParameters);
			}
			catch (System.Exception ex)
			{
				this.bangoLogger.LogInternalErrorCritical(ex);
			}
		}

		/// <summary>
		/// Initiates logger and posts events, this must be called to log session start events 
		/// </summary>
		/// <param name="applicationKey">The Application Key that has been set up for the application using the management tools.</param>
		public void initialize(System.String applicationKey)
		{
			this.bangoLogger.InitLogger(applicationKey);
			this.bangoLogger.PostEvents(false);
		}
				
		/// <summary>
		/// Initiates logging, this must be called after the configuration methods but before any other logging or any other session methods.
		/// </summary>
		/// <param name="applicationKey">The Application Key that has been set up for the application using the management tools.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void startSession(System.String applicationKey, System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			initialize(applicationKey);
			this.bangoLogger.LogEventStart(eventValue, eventDetail, eventParameters);
		}

		#endregion

		#region End Session

		/// <summary>
		/// Indicates that the session has ended.
		/// </summary>
		public void onEndSession()
		{
			onEndSession("", "", null);
		}

		/// <summary>
		/// Indicates that the session has ended.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		public void onEndSession(System.String eventValue)
		{
			onEndSession(eventValue, "", null);
		}

		/// <summary>
		/// Indicates that the session has ended.
		/// </summary>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onEndSession(System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onEndSession("", "", eventParameters);
		}

		/// <summary>
		/// Indicates that the session has ended.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onEndSession(System.String eventValue, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onEndSession(eventValue, "", eventParameters);
		}

		/// <summary>
		/// Indicates that the session has ended.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onEndSession(System.String eventValue, System.String eventDetail)
		{
			onEndSession(eventValue, eventDetail, null);
		}
		/// <summary>
		/// Indicates that the session has ended.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onEndSession(System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			try
			{
				endSession(eventValue, eventDetail, eventParameters);
			}
			catch (System.Exception ex)
			{
				this.bangoLogger.LogInternalErrorCritical(ex);
			}
		}

		/// <summary>
		/// uninitiates logging events, this must be called to log end session events
		/// </summary>
		public void Uninitialize()
		{ 
			this.bangoLogger.SaveProfile();			
			this.bangoLogger.EndLocationUpdates();
		
		}

		/// <summary>
		/// Indicates that the session has ended.
		/// </summary>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void endSession(System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			
			this.bangoLogger.LogEventEnd(eventValue, eventDetail, eventParameters);
			Uninitialize();
			
		}

		#endregion

		#region Idle

		/// <summary>
		/// Indicates that the session has entered an idle state, for example the application has lost focus.
		/// </summary>
		public void onIdle()
		{
			onIdle("", "", null);
		}

		/// <summary>
		/// Indicates that the session has entered an idle state, for example the application has lost focus.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		public void onIdle(System.String eventValue)
		{
			onIdle(eventValue, "", null);
		}

		/// <summary>
		/// Indicates that the session has entered an idle state, for example the application has lost focus.
		/// </summary>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onIdle(System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onIdle("", "", eventParameters);
		}

		/// <summary>
		/// Indicates that the session has entered an idle state, for example the application has lost focus.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		public void onIdle(System.String eventValue, System.String eventDetail)
		{
			onIdle(eventValue, eventDetail, null);
		}

		/// <summary>
		/// Indicates that the session has entered an idle state, for example the application has lost focus.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onIdle(System.String eventValue, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onIdle(eventValue, "", eventParameters);
		}

		/// <summary>
		/// Indicates that the session has entered an idle state, for example the application has lost focus.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onIdle(System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			try
			{
				this.bangoLogger.LogEvent(BangoSessionEvents.SESSION_IDLE_START, eventValue, eventDetail, eventParameters);
				this.bangoLogger.SaveProfile();
			}
			catch (System.Exception)
			{
			}
		}

		#endregion

		#region Resume

		/// <summary>
		/// Indicates that the session has resumed after an idle state, for example the application has gained focus after losing focus.
		/// </summary>
		public void onResume()
		{
			onResume("", "", null);
		}

		/// <summary>
		/// Indicates that the session has resumed after an idle state, for example the application has gained focus after losing focus.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		public void onResume(System.String eventValue)
		{
			onResume(eventValue, "", null);
		}

		/// <summary>
		/// Indicates that the session has resumed after an idle state, for example the application has gained focus after losing focus.
		/// </summary>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onResume(System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onResume("", "", eventParameters);
		}

		/// <summary>
		/// Indicates that the session has resumed after an idle state, for example the application has gained focus after losing focus.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		public void onResume(System.String eventValue, System.String eventDetail)
		{
			onResume(eventValue, eventDetail, null);
		}

		/// <summary>
		/// Indicates that the session has resumed after an idle state, for example the application has gained focus after losing focus.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onResume(System.String eventValue, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onResume(eventValue, "", eventParameters);
		}

		/// <summary>
		/// Indicates that the session has resumed after an idle state, for example the application has gained focus after losing focus.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onResume(System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			try
			{
				this.bangoLogger.ReloadProfile();
				this.bangoLogger.LogEvent(BangoSessionEvents.SESSION_IDLE_END, eventValue, eventDetail, eventParameters);
			}
			catch (System.Exception) { }
		}

		#endregion

		#endregion

		#region Logging Events

		#region Log Event

		/// <summary>
		/// Logs a generic event.
		/// </summary>
		/// <param name="eventName">The event name is identifier for the type of event that you would like to record. You can create your own event names simply sending it in this field.</param>
		public void onEvent(System.String eventName)
		{
			onEvent(eventName, "", "", null);
		}

		/// <summary>
		/// Logs a generic event.
		/// </summary>
		/// <param name="eventName">The event name is identifier for the type of event that you would like to record. You can create your own event names simply sending it in this field.</param>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		public void onEvent(System.String eventName, System.String eventValue)
		{
			onEvent(eventName, eventValue, "", null);
		}

		/// <summary>
		/// Logs a generic event.
		/// </summary>
		/// <param name="eventName">The event name is identifier for the type of event that you would like to record. You can create your own event names simply sending it in this field.</param>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		public void onEvent(System.String eventName, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onEvent(eventName, "", "", eventParameters);
		}

		/// <summary>
		/// Logs a generic event.
		/// </summary>
		/// <param name="eventName">The event name is identifier for the type of event that you would like to record. You can create your own event names simply sending it in this field.</param>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		public void onEvent(System.String eventName, System.String eventValue, System.String eventDetail)
		{
			onEvent(eventName, eventValue, eventDetail, null);
		}

		/// <summary>
		/// Logs a generic event.
		/// </summary>
		/// <param name="eventName">The event name is identifier for the type of event that you would like to record. You can create your own event names simply sending it in this field.</param>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onEvent(System.String eventName, System.String eventValue, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onEvent(eventName, eventValue, null, eventParameters);
		}

		/// <summary>
		/// Logs a generic event.
		/// </summary>
		/// <param name="eventName">The event name is identifier for the type of event that you would like to record. You can create your own event names simply sending it in this field.</param>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onEvent(System.String eventName, System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			try
			{
				this.bangoLogger.LogEvent(eventName, eventValue, eventDetail, eventParameters);
			}
			catch (System.Exception)
			{
			}
		}

		//public void onEvent(System.String eventName, System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		//{
		//    try
		//    {
		//        if (EventNameAllowed(eventName))
		//        {
		//            _bangoLogger.LogEvent(eventName, eventValue, eventDetail, eventParameters);
		//        }
		//    }
		//    catch (Exception ex)
		//    {
		//    }
		//}

		public bool EventNameAllowed(string eventName)
		{
			bool logAllowed = true;
			string[] events = null;

			if (_active_logging_level.Count > 0)
			{
				logAllowed = (eventName == BangoSessionEvents.SESSION_START) || (eventName == BangoSessionEvents.SESSION_END) || (eventName == BangoSessionEvents.SESSION_IDLE_START) || (eventName == BangoSessionEvents.SESSION_IDLE_END);
				if (!logAllowed)
				{
					foreach (int index in _active_logging_level)
					{
						events = _logging_level_events[index];
						if (events != null)
						{
							foreach (string str in events)
							{
								if (eventName == str)
									return true;
							}

						}

					}

				}

			}
			return logAllowed;
		}

		public void setLoggingLevel(BangoLoggingLevel.BangoLoggingLevelEnum loggingLevel)
		{
			_active_logging_level = getOrdinalIndices((int)loggingLevel);
		}

		public void setLoggingLevel(int loggingLevel)
		{
			_active_logging_level = this.getOrdinalIndices(loggingLevel);
		}

		public void setLoggingLevelEvents(BangoLoggingLevel.BangoLoggingLevelEnum loggingLevel, string[] eventList)
		{
			int enumIndex = this.getOrdinalIndex(loggingLevel);
			if ((enumIndex > -1) && (enumIndex < TOTAL_LEVELS))
			{
				_logging_level_events[enumIndex] = eventList;
			}
		}

		public int getOrdinalIndex(BangoLoggingLevel.BangoLoggingLevelEnum loggingLevel)
		{
			int value = (int)loggingLevel;
			List<int> indices = getOrdinalIndices(value);
			if (indices.Count == 0)
			{
				return -1;
			}
			return int.Parse(indices[0].ToString());
		}


		public List<int> getOrdinalIndices(int loggingLevel)
		{
			List<int> indices = new List<int>();
			int loopIndex = 0;
			foreach (int logLevelCounter in BangoLoggingLevel.values())
			{
				if (logLevelCounter != _setLoggingLevel)
				{
					if ((loggingLevel & logLevelCounter) == logLevelCounter)
					{
						indices.Add(loopIndex);
					}
					loopIndex++;
				}
			}
			return indices;
		}
		#endregion

		#region On Demand Video Start

		/// <summary>
		/// Logs an onDemandVideoStart event.
		/// </summary>
		public void onDemandVideoStart()
		{
			onDemandVideoStart("", "", null);
		}

		/// <summary>
		/// Logs an onDemandVideoStart event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		public void onDemandVideoStart(System.String eventValue)
		{
			onDemandVideoStart(eventValue, "", null);
		}

		/// <summary>
		/// Logs an onDemandVideoStart event.
		/// </summary>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onDemandVideoStart(System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onDemandVideoStart("", "", eventParameters);
		}

		/// <summary>
		/// Logs an onDemandVideoStart event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		public void onDemandVideoStart(System.String eventValue, System.String eventDetail)
		{
			onDemandVideoStart(eventValue, eventDetail, null);
		}

		/// <summary>
		/// Logs an onDemandVideoStart event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onDemandVideoStart(System.String eventValue, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onDemandVideoStart(eventValue, "", eventParameters);
		}

		/// <summary>
		/// Logs an onDemandVideoStart event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onDemandVideoStart(System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			try
			{
				if (eventParameters == null)
				{
					eventParameters = new System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>>();
				}
				eventParameters.Add(new System.Collections.Generic.KeyValuePair<System.String, System.String>(BangoConstants.VIDEO_PARAMETERNAME, BangoConstants.VIDEO_ONDEMANDPARAMETER));
				this.bangoLogger.LogEvent(BangoSessionEvents.EVENT_VIDEOSTART, eventValue, eventDetail, eventParameters);
			}
			catch (System.Exception)
			{
			}
		}

		#endregion

		#region On Demand Video Stop

		/// <summary>
		/// Logs an onDemandVideoStop event.
		/// </summary>
		public void onDemandVideoStop()
		{
			onDemandVideoStop("", "", null);
		}

		/// <summary>
		/// Logs an onDemandVideoStop event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		public void onDemandVideoStop(System.String eventValue)
		{
			onDemandVideoStop(eventValue, "", null);
		}

		/// <summary>
		/// Logs an onDemandVideoStop event.
		/// </summary>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onDemandVideoStop(System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onDemandVideoStop("", "", eventParameters);
		}

		/// <summary>
		/// Logs an onDemandVideoStop event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		public void onDemandVideoStop(System.String eventValue, System.String eventDetail)
		{
			onDemandVideoStop(eventValue, eventDetail, null);
		}

		/// <summary>
		/// Logs an onDemandVideoStop event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onDemandVideoStop(System.String eventValue, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onDemandVideoStop(eventValue, null, eventParameters);
		}

		/// <summary>
		/// Logs an onDemandVideoStop event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onDemandVideoStop(System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			try
			{
				if (eventParameters == null)
				{
					eventParameters = new System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>>();
				}
				eventParameters.Add(new System.Collections.Generic.KeyValuePair<System.String, System.String>(BangoConstants.VIDEO_PARAMETERNAME, BangoConstants.VIDEO_ONDEMANDPARAMETER));
				this.bangoLogger.LogEvent(BangoSessionEvents.EVENT_VIDEOSTOP, eventValue, eventDetail, eventParameters);
			}
			catch (System.Exception)
			{
			}
		}

		#endregion

		#region Live Video Start

		/// <summary>
		/// Logs an onLiveVideoStart event.
		/// </summary>
		public void onLiveVideoStart()
		{
			onLiveVideoStart("", "", null);
		}

		/// <summary>
		/// Logs an onLiveVideoStart event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		public void onLiveVideoStart(System.String eventValue)
		{
			onLiveVideoStart(eventValue, "", null);
		}

		/// <summary>
		/// Logs an onLiveVideoStart event.
		/// </summary>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onLiveVideoStart(System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onLiveVideoStart("", "", eventParameters);
		}

		/// <summary>
		/// Logs an onLiveVideoStart event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		public void onLiveVideoStart(System.String eventValue, System.String eventDetail)
		{
			onLiveVideoStart(eventValue, eventDetail, null);
		}

		/// <summary>
		/// Logs an onLiveVideoStart event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onLiveVideoStart(System.String eventValue, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onLiveVideoStart(eventValue, "", eventParameters);
		}

		/// <summary>
		/// Logs an onLiveVideoStart event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onLiveVideoStart(System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			try
			{
				if (eventParameters == null)
				{
					eventParameters = new System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>>();
				}
				eventParameters.Add(new System.Collections.Generic.KeyValuePair<System.String, System.String>(BangoConstants.VIDEO_PARAMETERNAME, BangoConstants.VIDEO_LIVEPARAMETER));
				this.bangoLogger.LogEvent(BangoSessionEvents.EVENT_VIDEOSTART, eventValue, eventDetail, eventParameters);
			}
			catch (System.Exception)
			{
			}
		}

		#endregion

		#region Live Video Stop

		/// <summary>
		/// Logs an onLiveVideoStop event.
		/// </summary>
		public void onLiveVideoStop()
		{
			onLiveVideoStop("", "", null);
		}

		/// <summary>
		/// Logs an onLiveVideoStop event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		public void onLiveVideoStop(System.String eventValue)
		{
			onLiveVideoStop(eventValue, "", null);
		}

		/// <summary>
		/// Logs an onLiveVideoStop event.
		/// </summary>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onLiveVideoStop(System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onLiveVideoStop("", "", eventParameters);
		}

		/// <summary>
		/// Logs an onLiveVideoStop event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		public void onLiveVideoStop(System.String eventValue, System.String eventDetail)
		{
			onLiveVideoStop(eventValue, eventDetail, null);
		}

		/// <summary>
		/// Logs an onLiveVideoStop event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onLiveVideoStop(System.String eventValue, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onLiveVideoStop(eventValue, "", eventParameters);
		}

		/// <summary>
		/// Logs an onLiveVideoStop event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onLiveVideoStop(System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			try
			{
				if (eventParameters == null)
				{
					eventParameters = new System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>>();
				}
				eventParameters.Add(new System.Collections.Generic.KeyValuePair<System.String, System.String>(BangoConstants.VIDEO_PARAMETERNAME, BangoConstants.VIDEO_LIVEPARAMETER));
				this.bangoLogger.LogEvent(BangoSessionEvents.EVENT_VIDEOSTOP, eventValue, eventDetail, eventParameters);

			}
			catch (System.Exception)
			{
			}

		}

		#endregion

		#region Search

		/// <summary>
		/// Logs a search event.
		/// </summary>
		public void onSearch()
		{
			onSearch("", "", null);
		}

		/// <summary>
		/// Logs a search event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		public void onSearch(System.String eventValue)
		{
			onSearch(eventValue, "", null);
		}

		/// <summary>
		/// Logs a search event.
		/// </summary>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onSearch(System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onSearch("", "", eventParameters);
		}

		/// <summary>
		/// Logs a search event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		public void onSearch(System.String eventValue, System.String eventDetail)
		{
			onSearch(eventValue, eventDetail, null);
		}

		/// <summary>
		/// Logs a search event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onSearch(System.String eventValue, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onSearch(eventValue, "", eventParameters);
		}

		/// <summary>
		/// Logs a search event.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onSearch(System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			try
			{
				this.bangoLogger.LogEvent(BangoSessionEvents.EVENT_SEARCH, eventValue, eventDetail, eventParameters);
			}
			catch (System.Exception)
			{
			}
		}

		#endregion

		#region Page view

		/// <summary>
		/// Increments the page view count.
		/// </summary>
		public void onPageView()
		{
			onPageView("", "", null);
		}

		/// <summary>
		/// Increments the page view count.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		public void onPageView(System.String eventValue)
		{
			onPageView(eventValue, "", null);
		}

		/// <summary>
		/// Increments the page view count.
		/// </summary>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onPageView(System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onPageView("", "", eventParameters);
		}

		/// <summary>
		/// Increments the page view count.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		public void onPageView(System.String eventValue, System.String eventDetail)
		{
			onPageView(eventValue, eventDetail, null);
		}

		/// <summary>
		/// Increments the page view count.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onPageView(System.String eventValue, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			onPageView(eventValue, "", eventParameters);
		}

		/// <summary>
		/// Increments the page view count.
		/// </summary>
		/// <param name="eventValue">This is a value that you can associate with the event.</param>
		/// <param name="eventDetail">Any extra detail that you would like to attach to the event.</param>
		/// <param name="eventParameters">A Collection of Event Parameters.</param>
		public void onPageView(System.String eventValue, System.String eventDetail, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> eventParameters)
		{
			try
			{
				this.bangoLogger.LogEvent(BangoSessionEvents.EVENT_PAGEVIEW, eventValue, eventDetail, eventParameters);
			}
			catch (System.Exception ex)
			{
			}
		}

		#endregion

		#region Error

		/**
		 * Logs an error event.
		 * @param errorId The id you want to assign to the error.
		 * @param message Any extra detail that you would like to attach to the error.
		 * @param errorClass The class the error occurred in.
		 */
		public void onError(System.String errorId, System.String message, System.String errorClass)
		{
			onError(errorId, message, errorClass, null);
		}

		/**
		 * Logs an error event.
		 * @param errorId The id you want to assign to the error.
		 * @param message Any extra detail that you would like to attach to the error.
		 * @param errorClass The class the error occurred in.
		 * @param eventParameters A hashtable collection of event parameters.
		 */
		public void onError(System.String errorId, System.String message, System.String errorClass, System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> errorParameters)
		{
			try
			{
				this.bangoLogger.LogEventError(errorId, message, errorClass, errorParameters);
			}
			catch (System.Exception ex)
			{
				this.bangoLogger.LogInternalErrorCritical(ex);
			}
		}

		#endregion

		#endregion

		#endregion

		#region Debugging

		public string viewBatch()
		{
			return this.bangoLogger.viewBatch();
		}

		#endregion
	}
}
